using System;
namespace APP.HELPER.Utils.BarcodeLib
{
	internal class MSI : BarcodeCommon, IBarcode
	{
		private string[] MSI_Code = new string[]
		{
			"100100100100",
			"100100100110",
			"100100110100",
			"100100110110",
			"100110100100",
			"100110100110",
			"100110110100",
			"100110110110",
			"110100100100",
			"110100100110"
		};
		private BarCodeStyles _encodedBarCodeStyles = BarCodeStyles.UNSPECIFIED;
		public string Encoded_Value
		{
			get
			{
				return this.Encode_MSI();
			}
		}
		public MSI(string input, BarCodeStyles encodedBarCodeStyles)
		{
			this._encodedBarCodeStyles = encodedBarCodeStyles;
			this.Raw_Data = input;
		}
		private string Encode_MSI()
		{
			if (!BarcodeEdit.CheckNumericOnly(this.Raw_Data))
			{
				throw new Exception("EMSI-1: Numeric Data Only");
			}
			string text = this.Raw_Data;
			string text4;
			if (this._encodedBarCodeStyles == BarCodeStyles.MSI_Mod10 || this._encodedBarCodeStyles == BarCodeStyles.MSI_2Mod10)
			{
				string text2 = "";
				string text3 = "";
				for (int i = text.Length - 1; i >= 0; i -= 2)
				{
					text2 = text[i].ToString() + text2;
					if (i - 1 >= 0)
					{
						text3 = text[i - 1].ToString() + text3;
					}
				}
				text2 = Convert.ToString(int.Parse(text2) * 2);
				int num = 0;
				int num2 = 0;
				text4 = text3;
				for (int j = 0; j < text4.Length; j++)
				{
					num += int.Parse(text4[j].ToString());
				}
				text4 = text2;
				for (int j = 0; j < text4.Length; j++)
				{
					num2 += int.Parse(text4[j].ToString());
				}
				text += (10 - (num2 + num) % 10).ToString();
			}
			if (this._encodedBarCodeStyles == BarCodeStyles.MSI_Mod11 || this._encodedBarCodeStyles == BarCodeStyles.MSI_Mod11_Mod10)
			{
				int num3 = 0;
				int num4 = 2;
				for (int i = text.Length - 1; i >= 0; i--)
				{
					if (num4 > 7)
					{
						num4 = 2;
					}
					num3 += int.Parse(text[i].ToString()) * num4++;
				}
				text += (11 - num3 % 11).ToString();
			}
			if (this._encodedBarCodeStyles == BarCodeStyles.MSI_2Mod10 || this._encodedBarCodeStyles == BarCodeStyles.MSI_Mod11_Mod10)
			{
				string text2 = "";
				string text3 = "";
				for (int i = text.Length - 1; i >= 0; i -= 2)
				{
					text2 = text[i].ToString() + text2;
					if (i - 1 >= 0)
					{
						text3 = text[i - 1].ToString() + text3;
					}
				}
				text2 = Convert.ToString(int.Parse(text2) * 2);
				int num = 0;
				int num2 = 0;
				text4 = text3;
				for (int j = 0; j < text4.Length; j++)
				{
					num += int.Parse(text4[j].ToString());
				}
				text4 = text2;
				for (int j = 0; j < text4.Length; j++)
				{
					num2 += int.Parse(text4[j].ToString());
				}
				text += (10 - (num2 + num) % 10).ToString();
			}
			string str = "110";
			text4 = text;
			for (int j = 0; j < text4.Length; j++)
			{
				char c = text4[j];
				str += this.MSI_Code[int.Parse(c.ToString())];
			}
			return str + "1001";
		}
	}
}
